#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：python_learning 
@File ：singletons.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2024/6/4 下午3:15 
"""

import functools


def singleton(cls):
	"""Make a class a Singleton class (only one instance)"""

	@functools.wraps(cls)
	def wrapper_singleton(*args, **kwargs):
		if not wrapper_singleton.instance:
			wrapper_singleton.instance = cls(*args, **kwargs)
		return wrapper_singleton.instance

	wrapper_singleton.instance = None
	return wrapper_singleton


@singleton
class TheOne:
	pass


if __name__ == '__main__':
	first_one = TheOne()
	second_one = TheOne()

	id(first_one)
	id(second_one)

	print(first_one is second_one)
